package com.james.wee.shuangseqiu.compre;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.james.wee.shuangseqiu.bo.IDBBo;
import com.james.wee.shuangseqiu.bo.OpenNumber;
import com.james.wee.shuangseqiu.db.DB;
import com.james.wee.shuangseqiu.open.OpenData;

public class SuccByQINum {
	// private static Map<Integer, Integer> rm = new HashMap<Integer,
	// Integer>();
	// private static List<String> rm = new ArrayList<String>();

	public static void print(Map<String, Integer> values, String openNum,
			String openno) {
		String printStr = "####################"
				+ openno
				+ "####################\n"
				+ "#  t01  t02  t03  t04  t05  t06  t07  t08  t09  t10  t11  #\n"
				+ "#  01  02  03  04  05  06  07  08  09  10  11  #\n"
				+ "#  01k  02k  03k  04k  05k  06k  07k  08k  09k  10k  11k  #\n"
				+

				"#  t12  t13  t14  t15  t16  t17  t18  t19  t20  t21  t22  #\n"
				+ "#  12  13  14  15  16  17  18  19  20  21  22  #\n"
				+ "#  12k  13k  14k  15k  16k  17k  18k  19k  20k  21k  22k  #\n"
				+

				"#  t23  t24  t25  t26  t27  t28  t29  t30  t31  t32  t33  #\n"
				+ "#  23  24  25  26  27  28  29  30  31  32  33  #\n"
				+ "#  23k  24k  25k  26k  27k  28k  29k  30k  31k  32k  33k  #\n"
				+ "----------------------------------------------\n"
				+ "出现5次的占有开奖号：p5\n" + "出现4次的占有开奖号：p4\n" + "出现3次的占有开奖号：p3\n"
				+ "出现2次的占有开奖号：p2\n" + "出现1次的占有开奖号：p1\n" + "出现0次的占有开奖号：p0\n"
				+ "##############################################";
		;
		String key = "";
		int index5 = 0;
		int index4 = 0;
		int index3 = 0;
		int index2 = 0;
		int index1 = 0;
		int index0 = 0;

		for (int i = 1; i <= 33; i++) {
			if (i < 10)
				key = "0" + i;
			else
				key = "" + i;
			int val = null == values.get(key) ? 0 : values.get(key);
			if (val < 10)
				printStr = printStr.replace("t" + key, " " + val);
			else
				printStr = printStr.replace("t" + key, "" + val);
			if (openNum.indexOf(key) != -1) {
				printStr = printStr.replace(key + "k", "▲ ");
				if (val == 5)
					index5++;
				else if (val == 4)
					index4++;
				else if (val == 3)
					index3++;
				else if (val == 2)
					index2++;
				else if (val == 1)
					index1++;
				else if (val == 0)
					index0++;
			} else {
				printStr = printStr.replace(key + "k", "  ");
			}
			// if (rm.get(5) < index5)
			// rm.put(5, index5);
			// if (rm.get(4) < index4)
			// rm.put(4, index4);
			// if (rm.get(3) < index3)
			// rm.put(3, index3);
			// if (rm.get(2) < index2)
			// rm.put(2, index2);
			// if (rm.get(1) < index1)
			// rm.put(1, index1);
			// if (rm.get(0) < index0)
			// rm.put(0, index0);
		}
		printStr = printStr.replace("p5", "" + index5);
		printStr = printStr.replace("p4", "" + index4);
		printStr = printStr.replace("p3", "" + index3);
		printStr = printStr.replace("p2", "" + index2);
		printStr = printStr.replace("p1", "" + index1);
		printStr = printStr.replace("p0", "" + index0);
		// rm.add(""+index5+index4+index3+index2+index1+index0);
		System.out.println(printStr);
	}

	public static void zuma(String sixred) throws Exception {
		if (sixred.indexOf("34") != -1) {
			System.out.println("共同红球：");
			return;
		}
		OpenData pd = new OpenData();
		String zumaIDS = pd.queryCardNoByLastOpenData(sixred);
		System.out.print("共同红球：" + pd.querySelectNo(zumaIDS) + "\n");
	}

	public static void zumaIds(String ids) throws Exception {
		OpenData pd = new OpenData();
		System.out.print("共同红球：" + pd.querySelectNo(ids) + "\n");
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		String ids = "13,14,18";
//		try {
//			zumaIds(ids);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		try {
			List<IDBBo> list = DB.getInstance().queryBoList(
					"SELECT * FROM OpenNumber    ORDER BY ID DESC limit 0,100",
					OpenNumber.class);
			OpenNumber openobj = null;
			OpenNumber desc = null;
			Map<String, Integer> values = null;// new HashMap<String,
												// Integer>();
			for (int j = -1, lens = list.size() - 10; j < lens; j++) {
				values = new HashMap<String, Integer>();
				if (j == -1) {
					String s = ((OpenNumber) list.get(0)).getOpennum();
					openobj = new OpenNumber("" + (Integer.parseInt(s) + 1),
							"34", "34", "34", "34", "34", "34", null, 0, null,
							null);
				} else {
					openobj = (OpenNumber) list.get(j);
				}
				for (int i = j + 1, len = j + 10; i <= len; i++) {
					desc = (OpenNumber) list.get(i);
					String[] ses = desc.sixRedNum().split(",");
					for (String s : ses)
						if (null != values.get(s)) {
							values.put(s, (values.get(s).intValue() + 1));
						} else {
							values.put(s, 1);
						}
				}
				print(values, openobj.sixRedNum(), openobj.getOpennum());
				zuma(openobj.sixRedNum());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
